package com.swh.dao;

import com.swh.dao.base.BaseDao;
import com.swh.entity.QualificationCondition;
import com.swh.entity.SysResource;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/28 16:19
 * @Version: 1.0
 */
public interface SysResourceDao extends BaseDao<SysResource> {
    @Override
    int insert(SysResource sysResource);

    @Override
    int delete(int id);

    @Override
    int update(SysResource sysResource);

    @Override
    SysResource load(int id);

    @Override
    List<SysResource> pageList(int offset, int pageSize);

    @Override
    int pageListCount(int offset, int pageSize);

    List<Map> selectPage(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize,
                         @Param("condition") QualificationCondition condition);


    List<SysResource> findAll();

    @Select(" SELECT " +
            "  * " +
            "  FROM " +
            "  sys_resource " +
            "  WHERE " +
            "  type = 0 " +
            "  AND common = 0 " +
            "  AND del_flag = 0 " +
            "        AND url <> ''")
    List<SysResource> selectResources();

    @Select("SELECT DISTINCT " +
            " sre.* " +
            "FROM " +
            " sys_user_role sur, " +
            " sys_role sro, " +
            " sys_role_resource srr, " +
            " sys_resource sre  " +
            "WHERE " +
            " sur.user_id = #{uid}  " +
            " AND sre.del_flag = 0  " +
            " AND sre.type = 0  " +
            " AND sur.role_id = sro.id  " +
            " AND srr.resource_id = sre.id  " +
            "ORDER BY sort ASC ")
    List<SysResource> selectByUid(long uid);
}
